class Solution {
public:
    int search(vector<int>& nums, int target) {
        if (nums.size() == 0)
            return -1;
        int left = 0;
        int right = nums.size() - 1;
        int min = (left + right) / 2;
        while (left <= right)
        {
            if (target == nums[min])
                return min;
            else if (target < nums[min])
                right = min - 1;
            else if (target > nums[min])
                left = min + 1;
            min = (left + right) / 2;
        }
        return -1;
    }
};